﻿// Write a program that finds the maximal increasing sequence in an array.
// Example: {3, 2, 3, 4, 2, 2, 4} -> {2, 3, 4}

using System;

class FindMaxIncreaseElementSequence
{
    static void Main()
    {
        Console.Write("Enter array lenght: ");
        int arraySize = int.Parse(Console.ReadLine());

        int[] intArray = new int[arraySize];
        for (int i = 0; i < intArray.Length; i++)
        {
            Console.Write("Enter element {0} from array: ", i + 1);
            intArray[i] = int.Parse(Console.ReadLine());
        }

        int firstElementIndex = 0;
        int maxSequencedNumberCount = 0;
        int sequenceNumbersCount = 1;
        bool equalSequence = false;
        int previousElement = intArray[0];
        if (intArray.Length != 1)
        {
            for (int i = 1; i < intArray.Length; i++)
            {
                if (previousElement < intArray[i])
                {
                    sequenceNumbersCount++;
                    if (sequenceNumbersCount > maxSequencedNumberCount)
                    {
                        maxSequencedNumberCount = sequenceNumbersCount;
                        if (sequenceNumbersCount == 2)
                        {
                            firstElementIndex = i - 1;
                        }
                        equalSequence = false;
                    }
                    else if (sequenceNumbersCount == maxSequencedNumberCount)
                    {
                        // if more than one equal sequence
                        equalSequence = true;
                    }
                }
                else
                {
                    sequenceNumbersCount = 1;
                }
                previousElement = intArray[i];
            }
        }
        else
        {
            firstElementIndex = 0;
            maxSequencedNumberCount = 1;
            sequenceNumbersCount = 0;
        }

        if (firstElementIndex == 0)
        {
            maxSequencedNumberCount--;
        }

        if (maxSequencedNumberCount > 1 && !equalSequence)
        {
            Console.Write("The maximal increasing sequence of elements: {");
            for (int i = firstElementIndex; i <= maxSequencedNumberCount; i++)
            {
                Console.Write(intArray[i]);
                if (i < maxSequencedNumberCount)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine("}");
        }
        else if (equalSequence)
        {
            Console.WriteLine("More than one increasing sequence of elements");
        }
        else
        {
            Console.WriteLine("Increasing sequence of elements not exist");
        }
    }
}